Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding date filter to GetNodesCounts API #3586

Merged
merged 5 commits into from
May 6, 2020

Conversation

lancewf
Copy link
Contributor

@lancewf lancewf commented May 4, 2020

🔩 Description: What code changed, and why?

Adding date filters to the GetNodesCounts allows a user to filter on nodes that have check-in between a specific period. This was added for the insight UI control for the Desktop view.

⛓️ Related Resources

#3372

👟 How to Build and Test the Change

  1. build components/config-mgmt-service && build components/automate-gateway && start_all_services
  2. Add some nodes with decreasing check-in dates with this command for i in {1..5}; do generate_chef_run_example | jq --arg d $(date +%FT%TZ -d "$i day ago") '.end_time=$d' | send_chef_data_raw; done
  3. To get the node counts for three days ago to a day ago run curl -f --insecure -H "api-token: $(get_api_token)" --data-urlencode "start=$(date +%FT%TZ -d '3 day ago')" --data-urlencode "end=$(date +%FT%TZ -d '1 day ago')" https://localhost/api/v0/cfgmgmt/stats/node_counts | jq
  4. Ensure the response looks like below.
{
  "total": 2,
  "success": 0,
  "failure": 0,
  "missing": 2
}

✅ Checklist

Signed-off-by: Lance Finfrock <[email protected]>
Signed-off-by: Lance Finfrock <[email protected]>
@lancewf lancewf force-pushed the lancewf/getnodescount_date_filters branch from 1cf00d2 to 1f808d9 Compare May 5, 2020 18:08
Lance Finfrock added 3 commits May 5, 2020 11:52
var ns = *new(backend.NodesCounts)

// Adding the exists = true filter to the list of filters, because nodes
// have documents that persist in elasticsearch to hold historical data
// even after the node no longer exists
filters["exists"] = []string{"true"}

boolQuery := newBoolQueryFromFilters(filters)
mainQuery := newBoolQueryFromFilters(filters)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the main change with this PR. The rest is passing the start and end date to this function.

@@ -461,13 +461,43 @@ func TestStatsNodesCountsWhen20Nodes(t *testing.T) {
func TestStatsNodesCountsFilteringWithTableDriven(t *testing.T) {
dataNodes := []struct {
number int
node iBackend.NodeInfo
node iBackend.Node
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated this to be a node to allow for Checkin datetime variation.

@lancewf lancewf marked this pull request as ready for review May 6, 2020 00:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants